package com.bjdd.jdy.ui.videoExam;

import com.bjdd.jdy.util.SpUtil;
import com.bjdd.jdy.util.T;

/**
 * Created by Administrator on 2017/5/26.
 */

public class VideoExamPresenter extends VideoExamContract.Presenter {
    @Override
    public void commitExam(int chapter) {
        String token = SpUtil.getToken();
        String carrierId = SpUtil.getUser().getCarrierId();
        rxManager.add(model.commitExam(token,chapter,carrierId)
                .subscribe(result -> {
                    if (!result.isError()){
                        view.passExam();
                    }else {
                        T.show(result.getMsg());
                    }
                },e -> {
                    T.show("提交失败");
                }));
    }

    @Override
    public void getVideoURL(int type) {
        showLoadingDialog(false);
        String token = SpUtil.getToken();
        rxManager.add(model.getVideoURL(token,type)
        .subscribe(result -> {
            hideLoadingDialog();
            if (!result.isError()){
                view.urlBack(result.getData().getResourceUrl());
            }else {
                T.show(result.getMsg());
            }
        },e -> {
            hideLoadingDialog();
            T.show("获取视频资源失败");
        }));
    }

    @Override
    public void onStart() {

    }
}
